package com.yiwei.ydd.adapter;

import android.content.Context;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.allen.library.SuperButton;
import com.bumptech.glide.Glide;
import com.yiwei.ydd.R;
import com.yiwei.ydd.api.model.BanksListModel;

import butterknife.BindView;
import butterknife.ButterKnife;


/**
 * Created by xsooy-pc on 2017/10/23.
 */

public class BankListAdapter extends ItemAdapter<BanksListModel.DatasBean, BankListAdapter.DefaultHolder> {


    private Context context;

    public BankListAdapter(Context context) {
        super(context);
        this.context = context;
    }

    @Override
    public DefaultHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new DefaultHolder(inflate(R.layout.item_bank_list, parent));
    }

    @Override
    public void onBindViewHolder(DefaultHolder holder, int position) {
        BanksListModel.DatasBean item = getItem(position);
        holder.txtBank.setText(item.name);
        holder.txtCard.setText(item.bankcard);
        Glide.with(context).load(item.icon).into(holder.imgIcon);
        holder.btnBgColor.setShapeGradientStartColor(Color.parseColor(item.left_color)).setShapeGradientEndColor(Color.parseColor(item.right_color)).setShapeGradientOrientation(SuperButton.LEFT_RIGHT).setUseShape();
        holder.btnUnbind.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onChooseListener != null) {
                    onChooseListener.onClick(item.id);
                }
            }
        });
    }

    class DefaultHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.btn_bg_color)
        SuperButton btnBgColor;
        @BindView(R.id.img_icon)
        ImageView imgIcon;
        @BindView(R.id.txt_bank)
        TextView txtBank;
        @BindView(R.id.txt_card)
        TextView txtCard;
        @BindView(R.id.btn_unbind)
        TextView btnUnbind;

        public DefaultHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }

    private OnChooseListener onChooseListener;

    public void setOnChooseListener(OnChooseListener onChooseListener) {
        this.onChooseListener = onChooseListener;
    }

    public interface OnChooseListener {
        void onClick(String id);
    }
}
